package com.atguigu.spzx.cloud.order.controller;

import com.atguigu.spzx.cloud.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.atguigu.spzx.cloud.order.entity.Order;

import java.util.List;

@RestController
@RequestMapping(value = "/api/order")
public class OrderController {

    @Autowired
    private OrderService orderService ;

    @GetMapping(value = "/findOrderByOrderId/{orderId}")
    public Order findOrderByOrderId(@PathVariable("orderId") Long orderId
            , @RequestHeader(required = false) String hehe
            , @RequestHeader(required = false) String hehe1
            , @RequestHeader(required = false) String host
            , @RequestHeader(required = false) String pragma
            , @RequestHeader(required = false) String xxxxx
    ) {
        System.out.println("orderId = " + orderId + ", hehe = " + hehe + ", hehe1 = " + hehe1 + ", host = " + host + ", pragma = " + pragma + ", xxxxx = " + xxxxx);
        return orderService.findOrderByOrderId(orderId) ;
    }

    @GetMapping(value = "/findOrder/{orderId}")
    public Order findOrder(@PathVariable("orderId") Long orderId) {
        Order order = orderService.getById(orderId);
        return  order;
    }


    //todo: 保存订单集合 post /api/order/save/batch [{},{},{}] -> boolean
    @PostMapping("/save/batch")
    public boolean saveBatch(@RequestBody List<Order> orderList){
        boolean b = orderService.saveBatch(orderList);
        return b;
    }

}